package com.opal.jx.controller;

import com.opal.consts.WSC;
import com.opal.domain.R;
import com.opal.jx.entity.JxAssessReception;
import com.opal.jx.entity.table.JxEmp;
import com.opal.jx.exception.JxAssessException;
import com.opal.jx.service.JxWLBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 物流部
 */
@Controller
@RequestMapping("/jx/wlb")
public class JxWLBController {
    @Autowired
    private JxWLBService jxWLBService;

    /**
     * 根据部门code获取员工数据
     */
    @RequestMapping("queryEmp")
    @ResponseBody
    public Object queryEmp(String pkDept){
        return jxWLBService.selectEmpAndDept(pkDept);
    }

    /**
     * 获取PMC部门当月绩效数据
     */
    @RequestMapping("queryJxAssessWlbPmc")
    @ResponseBody
    public Object queryJxAssessWlbPmc(Integer year,Integer month,Integer type){
        return jxWLBService.queryJxAssessWlbPmcAndYearAndMonth(year,month,type);
    }

    /**
     * 添加物流部-pmc部门数据
     * @param jxAssessReception
     * @return
     */
    @RequestMapping("addPmcData")
    @ResponseBody
    public Object addPmcData(@RequestBody JxAssessReception jxAssessReception){
        return jxWLBService.addPmcData(jxAssessReception);
    }

    //成品科
    /**
     * 成品科-查询不是管理层的员工
     * @param pkDept
     * @return
     */
    @RequestMapping("selectCpkEmpByDeptAndNotInPostId")
    @ResponseBody
    List<JxEmp> selectCpkEmpByDeptAndNotInPostId(String pkDept){
        return jxWLBService.selectCpkEmpByDeptAndNotInPostId(pkDept);
    }

    /**
     * 成品科-查询管理层的员工
     * @return
     */
    @RequestMapping("selectCpkEmpByDeptAndInPostId")
    @ResponseBody
    List<JxEmp> selectCpkEmpByDeptAndInPostId(String pkDept){
        return jxWLBService.selectCpkEmpByDeptAndInPostId(pkDept);
    }

    /**
     * 获取成品科部门当月绩效数据
     */
    @RequestMapping("queryJxAssessWlbCpk")
    @ResponseBody
    public Object queryJxAssessWlbCpk(Integer year,Integer month,Integer type){
        return jxWLBService.queryJxAssessWlbCpk(year,month,type);
    }

    /**
     * 成品科-查询管理层的员工
     * @return
     */
    @RequestMapping("addCpkData")
    @ResponseBody
    Object addCpkData(@RequestBody JxAssessReception jxAssessReception){
        return jxWLBService.addCpkData(jxAssessReception);
    }

    //配件组
    /**
     * 写死的语句，只用于配件部门;查询除了主管和组长的员工
     * @param pkDept
     * @return
     */
    @RequestMapping("selectPjzEmpNotZgAndZz")
    @ResponseBody
    List<JxEmp> selectPjzEmpNotZgAndZz(String pkDept){
        return jxWLBService.selectPjzEmpNotZgAndZz(pkDept);
    }

    /**
     * 写死的语句，只用于配件部门;查询主管和组长
     * @param pkDept
     * @return
     */
    @RequestMapping("selectPjzEmpSoAsZgAndZz")
    @ResponseBody
    List<JxEmp> selectPjzEmpSoAsZgAndZz(String pkDept){
        return jxWLBService.selectPjzEmpSoAsZgAndZz(pkDept);
    }

    /**
     * 获取配件组部门当月绩效数据
     */
    @RequestMapping("queryJxAssessWlbPjz")
    @ResponseBody
    public Object queryJxAssessWlbPjz(Integer year,Integer month,Integer type){
        return jxWLBService.queryJxAssessWlbPjz(year,month,type);
    }

    /**
     * 添加物流部-配件组部门数据
     * @param jxAssessReception
     * @return
     */
    @RequestMapping("addPjzData")
    @ResponseBody
    public Object addPjzData(@RequestBody JxAssessReception jxAssessReception){
        return jxWLBService.addPjzData(jxAssessReception);
    }

    //原材料
    /**
     * 写死的语句，只用于原材料部门;查询除了主管和叉车司机、清洁工
     * @param pkDept
     * @return
     */
    @RequestMapping("selectPjzEmpNotZgAndCcAndQj")
    @ResponseBody
    List<JxEmp> selectPjzEmpNotZgAndCcAndQj(String pkDept){
        return jxWLBService.selectPjzEmpNotZgAndCcAndQj(pkDept);
    }

    /**
     * 写死的语句，只用于原材料部门;查询主管和叉车司机、清洁工三个职务员工
     * @param pkDept
     * @return
     */
    @RequestMapping("selectPjzEmpSoAsZgAndCcAndQj")
    @ResponseBody
    List<JxEmp> selectPjzEmpSoAsZgAndCcAndQj(String pkDept){
        return jxWLBService.selectPjzEmpSoAsZgAndCcAndQj(pkDept);
    }

    /**
     * 获取原材料组部门当月绩效数据
     */
    @RequestMapping("queryJxAssessWlbYcl")
    @ResponseBody
    public Object queryJxAssessWlbYcl(Integer year,Integer month,Integer type){
        return jxWLBService.queryJxAssessWlbYcl(year,month,type);
    }

    /**
     * 添加物流部-配件组部门数据
     * @param jxAssessReception
     * @return
     */
    @RequestMapping("addYclData")
    @ResponseBody
    public Object addYclData(@RequestBody JxAssessReception jxAssessReception){
        return jxWLBService.addYclData(jxAssessReception);
    }

    /**
     * 异常返回消息
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public R exceptionMessage(RuntimeException e){
        e.printStackTrace();
        if (e instanceof JxAssessException){    //自定义的异常
            return new R(WSC.PRECONDITIONFAILED,((JxAssessException) e).getMsg());
        }

        return new R(WSC.PRECONDITIONFAILED,e.getMessage());
    }

}
